- passkey_tracking_entry_point = 1

= render ::Layouts::CrudComponent.new(s_('ProfilesAuthentication|Manage passkeys'),
  icon: 'key',
  count: @passkeys.length ) do |c|
  - c.with_actions do
    = render Pajamas::ButtonComponent.new(href: new_profile_passkey_path(entry_point: passkey_tracking_entry_point), size: :small, icon: 'passkey', disabled: !password_authentication_enabled_for_web?) do
      = s_('ProfilesAuthentication|Add passkey')
  - c.with_body do
    .table-holder
      %table.table.b-table.gl-table.b-table-stacked-md{ role: 'table' }
        %thead
          %tr
            %th= _('Name')
            %th= s_('ProfilesAuthentication|Added on')
            %th= s_('ProfilesAuthentication|Last used')
            %th= _('Actions')
        %tbody
          - if !password_authentication_enabled_for_web?
            %tr
              %td{ colspan: 4 }
                = render Pajamas::AlertComponent.new(title: s_('ProfilesAuthentication|Passkeys unavailable'),
                  dismissible: false,
                  variant: :warning ) do |c|
                  = c.with_body do
                    - doc_link = link_to '', help_page_path('administration/settings/sign_in_restrictions.md', anchor: 'password-authentication-enabled'), target: '_blank', rel: 'noopener noreferrer'
                    = safe_format(s_('ProfilesAuthentication|To use passkeys, an administrator must allow password authentication. %{link_start}Learn more%{link_end}.'), tag_pair(doc_link, :link_start, :link_end))

          - elsif @passkeys.present?
            - @passkeys.each do |passkey|
              %tr
                %td{ data: { label: _('Name') } }= passkey[:name]
                %td{ data: { label: s_('ProfilesAuthentication|Added on') } }= l(passkey[:created_at].to_date, format: :admin)
                %td{ data: { label: s_('ProfilesAuthentication|Last used') } }= passkey[:last_used_at] ? l(passkey[:last_used_at].to_date, format: :admin) : ''
                %td{ data: { label: _('Actions') }, class: '!gl-py-3' }
                  .js-two-factor-action-confirm{ data: delete_passkey_data(current_password_required?, passkey[:delete_path], @passkeys.size) }
          - else
            %tr
              %td{ colspan: 4 }
                = s_('ProfilesAuthentication|No passkeys added.')
